package com.pengweiwei.androidzygote.goods.detail;

import android.content.Context;
import androidx.databinding.BaseObservable;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableInt;
import androidx.databinding.ObservableList;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.putong35.common.baseactfrag.CompState;
import com.putong35.common.baseactfrag.mvp.IMvpView;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by Administrator on 2017/7/24.
 */

public class GoodsDetailVM extends BaseObservable {

    private static final String TAG = GoodsDetailActivity.class.getSimpleName();
    private final Context mContext;
    private final IMvpView mMvpView;

    public final ObservableList<String> bannerImageListField = new ObservableArrayList<>();
    public ObservableField<String> costField = new ObservableField<>();
    public ObservableField<String> introductionField = new ObservableField<>();
    public ObservableField<String> durationField = new ObservableField<>();
    public ObservableField<String> soldCountField = new ObservableField<>();
    public ObservableInt pageItemSize = new ObservableInt();


    public GoodsDetailVM(Context context, IMvpView mvpView) {
        mContext = context.getApplicationContext();
        mMvpView = mvpView;
    }


    public void onShareBtnClicked(View view) {
        Log.e(TAG, "onShareBtnClicked: ");
    }

    public void onBackBtnClicked(View view) {
        Context context = view.getContext();
        if (context instanceof AppCompatActivity) {
            ((AppCompatActivity) context).finish();
        }
    }


    public void startLoading() {
        final String instruction = "XXXXXXXXXXXXXXxxxxxxxxxxxxXXXXXXXXX";
        final int duration = 45; // 45 minutes
        final int soldCount = 100;
        final float cost = 11.2f;

        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                costField.set(String.format("￥%1$.2f元", cost));
                introductionField.set(instruction);
                durationField.set(String.format("%1$d分钟", duration));
                soldCountField.set(String.format("已售%1$d", soldCount));
                bannerImageListField.add("http://img01.taopic.com/160203/235110-1602030ZP835.jpg");
                bannerImageListField.add("http://img01.taopic.com/160203/235110-1602030ZP835.jpg");
                bannerImageListField.add("http://img01.taopic.com/160203/235110-1602030ZP835.jpg");
                pageItemSize.set(3);
                mMvpView.setState(CompState.DATA);


            }
        }, 1000);




    }

}
